﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ProtoBuf;

/// <summary>
/// 工具类
/// </summary>
public class Util
{
    //protobuf序列化
    public static byte[] Serialize<T>(T t)
    {
        using (MemoryStream stream = new MemoryStream())
        {
            Serializer.Serialize(stream, t);
            return stream.ToArray();
        }
    }

    //protobuf反序列化
    public static T Deserialize<T>(byte[] bytes)
    {
        using (MemoryStream stream = new MemoryStream(bytes))
        {
            T t = Serializer.Deserialize<T>(stream);
            return t;
        }
    }
}
